package com.yzy.fly.mapper;

import com.yzy.fly.entity.core.FlyMethod;
import com.yzy.fly.kernel.mapper.FlyBasicMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;


@Mapper
public interface FlyMethodMapper extends FlyBasicMapper<FlyMethod> {
    @Select("select * from fly_method a where a.id = #{id}")
    FlyMethod selectById(@Param("id") int id);

    @Select("select * from fly_method a where 1=1")
    List<FlyMethod> selectAll();

    @Select("select * from fly_method a where 1=1 and a.classId = #{classId} order by a.seq asc")
    List<FlyMethod> selectAllByClassId(@Param("classId") int classId);

    @Select("select * from fly_method a where 1=1 and a.systemId = #{systemId}")
    List<FlyMethod> selectAllBySystemId(@Param("systemId") int systemId);

//    @Select({"select * from fly_method a where 1=1 and a.classId = (select b.fieldId from fly_field_annotation b where b.id = #{annotationId})",
//    "","",""})
    @Select({"<script>",
            "select * ",
            "from fly_method a",
            "where 1=1",
            "<when test='classId!=null'>",
            "AND a.classId = #{classId}",
            "</when>",
            "<when test='systemId!=null'>",
            "AND a.systemId = #{systemId}",
            "</when>",
            "</script>"})
    List<FlyMethod> selectAllByParentId(@Param("classId") Integer classId, @Param("systemId") Integer systemId);

    @Select("select * from fly_method a where 1=1 and a.name = #{name}")
    FlyMethod selectOneByName(@Param("name") String name);

}